﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FantasyBlog.Models;
using FantasyBlog.BLL;
using FantasyBlog.DAL;

namespace FantasyBlog.Controllers
{
    public class AdminOptionController : Controller
    {
        //
        // GET: /AdminOption/

        [Authorize(Roles = "admin")]
        public ActionResult Index()
        {
            AdminOptionModel m=new AdminOptionModel();
            m.SiteTitle = ProviderAFactory.SiteMetaData["site-title"];
            m.SiteDescription = ProviderAFactory.SiteMetaData["site-description"];
            m.SiteEMail = ProviderAFactory.SiteMetaData["site-email"];
            m.SiteURL = ProviderAFactory.SiteMetaData["site-url"];
            m.SitePicture = ProviderAFactory.SiteMetaData["site-picture"];
            m.PostPerPage = ProviderAFactory.SiteMetaData["post-per-page"];
            return View(m);
        }

        [HttpPost]
        [Authorize(Roles = "admin")]
        public ActionResult Modify(AdminOptionModel m)
        {
            ProviderAFactory.SiteMetaData["site-title"] = m.SiteTitle;
            ProviderAFactory.SiteMetaData["site-description"] = m.SiteDescription;
            ProviderAFactory.SiteMetaData["site-email"] = m.SiteEMail;
            ProviderAFactory.SiteMetaData["site-url"] = m.SiteURL;
            ProviderAFactory.SiteMetaData["site-picture"] = m.SitePicture;
            ProviderAFactory.SiteMetaData["post-per-page"] = m.PostPerPage;
            return RedirectToAction("Index");
        }
    }
}
